#include "HuntQuest.h"

HuntQuest::HuntQuest(void){
	numOfEnemiesKilled = 0;
	questMaxNum = 1;

	questStatus = ONGOING;
}

HuntQuest::~HuntQuest(void){
	for(vector<Enemy *>::iterator itr = (*EnemyList).begin(); itr != (*EnemyList).end(); ++itr){
		if((*itr) != NULL)
			delete (*itr);
	}
	(*EnemyList).clear();
}

void HuntQuest::InitQuest(Character *playerInfo, vector<Enemy *> *EnemyList, int NumberOfEnemyToKill, int questTimeSeconds){
	BaseQuest::InitQuest(playerInfo, "Kill enemies that are over populating!", questTimeSeconds);

	this->EnemyList = EnemyList;
	this->questMaxNum = NumberOfEnemyToKill;
}

void HuntQuest::RenderQuest(void){
	BaseQuest::RenderQuest();

	glPushMatrix();
		glScalef(0.4f, 0.4f, 1.0f);
		freetype::print(fontStyle, 300, 530, "%d/%d Killed", numOfEnemiesKilled, questMaxNum);
	glPopMatrix();
}

bool HuntQuest::UpdateQuest(Vector3D offset, float elapsed){
	for(vector<Enemy *>::iterator itr = (*EnemyList).begin(); itr != (*EnemyList).end(); ++itr){
		if((*itr)->GetLife() <= 0){
			numOfEnemiesKilled++;
		}
	}
	
	if(playerInfo->Check_Lives_Dead() || questTimer.CheckIfTimerEnd()){
		this->questStatus = BaseQuest::FAIL;
	}else if(numOfEnemiesKilled >= questMaxNum){
		this->questStatus = BaseQuest::COMPLETE;
	}

	return BaseQuest::UpdateQuest(offset, elapsed);
}